import { createStore } from 'vuex'

// 创建一个新的 store 实例
export default createStore({
    state () {
        return {
            currentUser_save: undefined,
        }
    },
    getters:{
        currentUser(state){
            if(!state.currentUser_save){
                return JSON.parse(localStorage.getItem('currentUser'))
            }else{
                return state.currentUser_save
            }
        }
    },
    mutations: {
        LOGIN (state, user) {
            state.currentUser_save = user
            localStorage.setItem('currentUser', JSON.stringify(user))
        },
        LOGOUT (state) {
            state.currentUser_save = undefined
        },
    },
    actions:{
        login (content, user) {
            content.commit("LOGIN", user)
        },
        logOut (content) {
            content.commit("LOGOUT")
        },
/*         getCurrentUser(content){
            if(!content.state.currentUser)
                return JSON.parse(localStorage.getItem('currentUser'))
            else
                return content.state.currentUser
        } */
    }
})